home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / wtjmarch.zip / CONTROLS.ZIP / NEWSTAT.C < prev    next >
Text File  |  1992-02-14  |  4KB  |  145 lines

  1. /*
  2.  * NEWSTAT.C  This file contains the static control window procedure
  3.  */
  4.  
  5. #include <windows.h>
  6. #include "statdll.h"
  7. #include "newstat.h"
  8.  
  9. void StaticDraw(HWND hwnd,HDC hdc)
  10. {
  11.     RECT    clientRect;
  12.     HANDLE    hCtrlText;
  13.     int     iStrLength;
  14.     LPSTR    lpstrText;
  15.     HFONT    hOldFont;
  16.     WORD    wStyle;
  17.     HBRUSH    hCtlColorBr,hNewBrush;
  18.     COLORREF    lOldColor;
  19.     HANDLE    hParentInst;
  20.     HICON    hIcon;
  21.     int     iOldMapMode;
  22.  
  23.     /* Obtain client window size and text                   */
  24.  
  25.     GetClientRect(hwnd,&clientRect);
  26.  
  27.     iStrLength = GetWindowTextLength(hwnd);
  28.     hCtrlText  = GlobalAlloc(GMEM_FIXED,iStrLength + 1);
  29.     lpstrText  = GlobalLock(hCtrlText);
  30.     GetWindowText(hwnd,lpstrText,iStrLength + 1);
  31.  
  32.     /* Send the WM_CTLCOLOR message to the parent allowing it to alter */
  33.     /* the background brush and the text color. If a brush is not      */
  34.     /* returned, used light gray as the background.               */
  35.  
  36.     hCtlColorBr = SendMessage(GetParent(hwnd),WM_CTLCOLOR,hdc,
  37.                      MAKELONG(hwnd,CTLCOLOR_STATIC));
  38.     hNewBrush = hCtlColorBr ? hCtlColorBr : GetStockObject(LTGRAY_BRUSH);
  39.  
  40.     /* Paint the background with using the new brush.               */
  41.  
  42.     FillRect(hdc,&clientRect,hNewBrush);
  43.  
  44.     /* If the static is an icon, the parent's icon is drawn but with   */
  45.     /* the background that has already been drawn.               */
  46.  
  47.     if ((GetWindowLong(hwnd,GWL_STYLE) & 0xf) == SS_ICON)
  48.     {
  49.     hParentInst = GetWindowWord(hwnd,GWW_HINSTANCE);
  50.     hIcon        = LoadIcon(hParentInst,lpstrText);
  51.     if (hIcon)
  52.     {
  53.         iOldMapMode = SetMapMode(hdc,MM_TEXT);
  54.         DrawIcon(hdc,clientRect.left,clientRect.top,hIcon);
  55.         SetMapMode(hdc,iOldMapMode);
  56.     }
  57.     GlobalFree(hCtrlText);
  58.     return;
  59.     }
  60.  
  61.     /* The background mode is set to transparent so the text does not  */
  62.     /* obliterate it, and the font is returned from the window extra   */
  63.     /* byte area.                               */
  64.  
  65.     SetBkMode(hdc,TRANSPARENT);
  66.     if (GET_STFONT != 0)
  67.        hOldFont = SelectObject(hdc,GET_STFONT);
  68.  
  69.     /* Determine the style settings.                       */
  70.  
  71.     wStyle = DT_VCENTER | DT_SINGLELINE;
  72.     if (IS_STYLE_SET(SS_CENTER))
  73.     wStyle |= DT_CENTER;
  74.     else if (IS_STYLE_SET(SS_RIGHT))
  75.     wStyle |= DT_RIGHT;
  76.     else wStyle |= DT_LEFT;
  77.  
  78.     /* For indented text, display white text one pixel offset to the   */
  79.     /* right and down.    For raised text, the white text is offset to   */
  80.     /* the left and up one pixel.                       */
  81.  
  82.     if (IS_STYLE_SET(SS_INDENT))
  83.     {
  84.     lOldColor = SetTextColor(hdc,RGB(255,255,255));
  85.     OffsetRect(&clientRect,1,1);
  86.     DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
  87.  
  88.     OffsetRect(&clientRect,-1,-1);
  89.     SetTextColor(hdc,lOldColor);
  90.     DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
  91.     }
  92.     else if (IS_STYLE_SET(SS_OUTDENT))
  93.     {
  94.     lOldColor = SetTextColor(hdc,RGB(255,255,255));
  95.     DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
  96.  
  97.     SetTextColor(hdc,lOldColor);
  98.     OffsetRect(&clientRect,1,1);
  99.     DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
  100.     OffsetRect(&clientRect,-1,-1);
  101.     }
  102.     else
  103.     DrawText(hdc,lpstrText,iStrLength,&clientRect,wStyle);
  104.  
  105.     if (GET_STFONT != 0 )
  106.        SelectObject(hdc,hOldFont);
  107.  
  108.     GlobalFree(hCtrlText);
  109.  
  110. }
  111.  
  112. LONG FAR PASCAL StaticWndFn(HWND hwnd, WORD message,WORD wParam, LONG lParam)
  113. {
  114.     HDC     hdc;
  115.     PAINTSTRUCT ps;
  116.  
  117.     switch (message)
  118.     {
  119.     case WM_SETFONT:
  120.  
  121.       /* Store the returned font handle in the window extra bytes. */
  122.  
  123.       SET_STFONT(wParam);
  124.       break;
  125.  
  126.     case WM_ERASEBKGND:
  127.  
  128.       /* The background is painted in the StaticDraw function.     */
  129.  
  130.       return TRUE;
  131.  
  132.     case WM_PAINT:
  133.  
  134.       hdc = BeginPaint(hwnd,&ps);
  135.       StaticDraw(hwnd,hdc);
  136.       EndPaint(hwnd,&ps);
  137.       return FALSE;
  138.  
  139.     default:
  140.       break;
  141.     }
  142.     return DefWindowProc (hwnd,message,wParam,lParam);
  143. }
  144. 
  145.